home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / e / mui22edev2.lha / Amiga_E / Sources / installhook.e < prev    next >
Text File  |  1994-10-10  |  1KB  |  44 lines

  1. /*
  2. ** installhook() - Use it like this:
  3. **
  4. **   MODULE 'utility/hooks'
  5. **
  6. **   PROC main()
  7. **    DEF myhook:hook
  8. **    installhook(myhook, {myhookfunc})
  9. **    /* do something with myhook */
  10. **   ENDPROC
  11. **
  12. **   PROC myhookfunc(hook,obj,msg)
  13. **    WriteF('hook:$\h, obj:\d, msg:\d\n',hook,obj,msg)
  14. **   ENDPROC
  15. **
  16. ** or if you don't need a ptr to the hook-structure:
  17. **
  18. **   PROC myhookfunc(obj,msg)
  19. **     WriteF('obj:\d, msg:\d\n',obj,msg)
  20. **   ENDPROC
  21. */
  22.  
  23. PROC installhook(hook,func)
  24.    DEF r
  25.    MOVE.L hook,A0
  26.    MOVE.L func,12(A0)    /* store address of func in hook.subentry */
  27.    LEA hookentry(PC),A1
  28.    MOVE.L A1,8(A0)    /* store address of hookentry in hook.entry */
  29.    MOVE.L A4,16(A0)    /* store ptr to vars in hook.data */
  30.    MOVE.L A0,r
  31. ENDPROC r
  32.  
  33. hookentry:
  34.   MOVEM.L D2-D7/A2-A6,-(A7)
  35.   MOVE.L 16(A0),A4    /* move ptr to vars to A4 */
  36.   MOVE.L A0,-(A7)    /* move ptr to hookstructure to the stack */
  37.   MOVE.L A2,-(A7)    /* move ptr to obj to the stack */
  38.   MOVE.L A1,-(A7)    /* move msg to the stack */
  39.   MOVE.L 12(A0),A0    /* move addr. of hookfunc. to A0 */
  40.   JSR (A0)        /* call hookfunc. */
  41.   LEA 12(A7),A7        /* remove the above from the stack */
  42.   MOVEM.L (A7)+,D2-D7/A2-A6
  43.   RTS            /* go back to the caller (MUI) */
  44.